package old.gui;

import java.util.ArrayList;

import utilities.SimpleHashMap;

import com.jme3.asset.AssetManager;
import com.jme3.system.AppSettings;

/*
 * Applies position and other status updates to GUIComponents
 * and GUIComponentPackages
 */

public class GUIUpdater {
	
	//public AppSettings settings;
	//public AssetManager assetManager;	
	GUILayout layout;
	
	
	public GUIUpdater(GUILayout layout)
	{
		this.layout = layout;
		//this.settings = layout.settings;
		//this.assetManager = layout.assetManager;
	}
	
	//change materials, textures, fonts, etc.
	/*public void updateComponent(GUIComponent component)
	{
		updateComponentPosition(component);
		//updateComponentVisuals(component);
		//fonts?
		//etc.
		
	}*/
	
	public void updateNodePosition(GUINode node)
	{
		int oldNodeX = node.getX();
		int oldNodeY = node.getY();
		int newNodeX;
		int newNodeY;
		
		int screenWidth = layout.settings.getWidth();
		int screenHeight = layout.settings.getHeight();
		
		newNodeX = oldNodeX * 
		
		
	}
	
	public void updateComponentPosition(GUIComponent component)
	{
		int oldCompWidth;
		int oldCompHeight;
		int newCompWidth;
		int newCompHeight;
		
		int newX;
		int newY;
		
		int oldScreenWidth;
		int oldScreenHeight;
		int newScreenWidth = settings.getWidth();
		int newScreenHeight = settings.getHeight();
		float currAspectRatio = (float) newScreenWidth/newScreenHeight;		
		
		oldScreenWidth = component.getScreenWidth();
		oldScreenHeight = component.getScreenHeight();
		oldCompWidth = component.getComponentWidth();
		oldCompHeight = component.getComponentHeight();
		
		if ((component.getAspectRatio() != currAspectRatio) ||
				(oldScreenWidth != newScreenWidth) ||
				(oldScreenHeight != newScreenHeight))
		{
			//change resolution of component
			component.setResolution(newScreenWidth, newScreenHeight);				
			
			//change height, width of component
			newCompWidth = oldCompWidth * newScreenWidth/oldScreenWidth;
			newCompHeight = oldCompHeight * newScreenHeight/oldScreenHeight;
			
			component.resize(newCompWidth,newCompHeight);
			
			//adjust XY location of component
			newX = component.getX() * oldScreenWidth/newScreenWidth;
			newY = component.getY() * oldScreenHeight/newScreenHeight;
			
			component.setXYLocation(newX, newY);
		}
		
	}
	
	

}
